<template>
    <div class="courseContentResourcesView">
        <div class="Resources" v-if="resourceId">
            <CourseContentResourceView v-model="resourceId"></CourseContentResourceView>
        </div>
    </div>
</template>

<script lang="ts">
import { ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import CourseContentResourceView from './courseContentResourcesView/CourseContentResourceView.vue';

export default {
    name: 'courseContentResourcesView'
}
</script>

<script setup lang="ts">
    const route = useRoute();
    const resourceId = ref(); // 获取资源Id参数
    // 参数转换函数（确保字符串转换为数字）
    const parseSafeInt = (value: string | string[] | undefined): number | undefined => {
        if (typeof value === 'string') {
            const num = parseInt(value, 10);
            return isNaN(num) ? undefined : num;
        }
        return undefined;
    };
    
    // 监听路由参数的变化
    watch(() => route.query.resourceId, async (newvValue) => {
        resourceId.value = parseSafeInt(newvValue);
        console.log("资源ID" + newvValue);
    },
    { immediate: true });
</script>

<style scoped>
.courseContentResourcesView {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    padding: 20px;
}
.Resources {
    width: 100%;
    height: 100%;
    display: flex;
    justify-items: center;
    align-items: flex-start;
}
.userAndDownloadBtn {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.user-info {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
}
.table {
    width: 100%;
    margin-top: 10px;
    border-radius: 5px;
}
.file-name {
  display: flex;
  align-items: center;
}

.file-icon {
  width: 20px;
  height: 20px;
  margin-right: 8px;
}

.download-btn {
  margin-top: 10px;
  width: 100px;
}
</style>